package com.cssw.fyzb.busi.api.user;

import com.cssw.fyzb.core.model.vo.user.UserAuthInfoVo;
import com.cssw.fyzb.busi.service.user.UserService;
import com.cssw.fyzb.core.dao.user.DistrictDao;
import com.cssw.fyzb.core.model.dodb.District;
import com.cssw.fyzb.core.model.dodb.User;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author zhouxu
 * @create 2020-12-25 15:43
 */
@Function(description = "用户认证信息查询", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "userID", required = true),
})
@Component
public class QueryUserAuthInfo implements Action {

    @Autowired
    private UserService userService;
    @Autowired
    private DistrictDao districtDao;

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        User user = userService.getById(userId);
        UserAuthInfoVo info = new UserAuthInfoVo();
        info.setUserName(user.getUserName());
        String idCard = user.getIdCard();
        info.setIdCard(idCard.substring(0,5)+"*********"+idCard.substring(14));
        // 地区名称
        if(user.getDistrict()!=null) {
            District district = districtDao.getByCode(user.getDistrict());
            if(district!=null) {
                info.setDistrict(district.getDistrictName());
            }
        }

        if(user.getCity()!=null) {
            District district = districtDao.getByCode(user.getCity());
            if(district!=null) {
                info.setCity(district.getDistrictName());
            }
        }

        if(user.getProvince()!=null) {
            District district = districtDao.getByCode(user.getProvince());
            if(district!=null) {
                info.setProvince(district.getDistrictName());
            }
        }

        return Response.success().put("data", info);
    }

}
